from sqlalchemy import create_engine
import tushare as ts
import time
import pandas as pd

def stoc(i):
    df = ts.get_realtime_quotes('600031') 
    data=[i]
    s1 = pd.Series(data, index=range(0,1,1))
    df['id'] = s1
    engine = create_engine('sqlite:///test.db', convert_unicode=True)

    #追加数据到现有表
    df.to_sql('tick_data',engine,if_exists='append')

i=0
while True:
    stoc(i)
    time.sleep(3)
    i=i+1
    print('insert %s datas'%i)
